package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.XlyProjectGroup;
import com.ruoyi.system.mapper.XlyProjectGroupMapper;
import com.ruoyi.system.service.IXlyProjectGroupService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 项目分组Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-02
 */
@Service
public class XlyProjectGroupServiceImpl extends MPJBaseServiceImpl<XlyProjectGroupMapper, XlyProjectGroup> implements IXlyProjectGroupService {

    /**
     * 查询项目分组列表
     *
     * @param xlyProjectGroup 项目分组
     * @return 项目分组
     */
    @Override
    public List<XlyProjectGroup> selectXlyProjectGroupList(XlyProjectGroup xlyProjectGroup) {
        List<XlyProjectGroup> xlyProjectGroupList = getBaseMapper().selectList(buildQueryWrapper(xlyProjectGroup));
        return xlyProjectGroupList;
    }

    private LambdaQueryWrapper<XlyProjectGroup> buildQueryWrapper(XlyProjectGroup query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<XlyProjectGroup> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getGroupName()), XlyProjectGroup::getGroupName, query.getGroupName());
        lqw.eq(query.getRelProjectId() != null, XlyProjectGroup::getRelProjectId, query.getRelProjectId());
        lqw.orderByDesc(XlyProjectGroup::getCreateTime);
        return lqw;
    }

}
